﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using Bussiness;
using Model;

namespace hostal
{
    public partial class AgregarConsumo : Form
    {
        DataTable temp = new DataTable();
        string habitacion;
        public AgregarConsumo(string h)
        {
            InitializeComponent();
            habitacion = h;
            label1.Text = "Consumo habitacion : " + h;
        }

        private void AgregarConsumo_Load(object sender, EventArgs e)
        {
            
            DGConsumo.Columns.Add("idproducto", "idproducto");
            DGConsumo.Columns.Add("nombre", "producto");
            //DataGridViewCheckBoxColumn cons = new DataGridViewCheckBoxColumn();
            //cons.DataPropertyName = "consumido";
            //cons.HeaderText = " ";
            //DGConsumo.Columns.Add(cons);
            DGConsumo.Columns.Add("cantidad", "cantidad");

            productoDataAccess dal = new productoDataAccess();
            temp = dal.buscarProductosFrigo();

            for (int i = 0; i < temp.Rows.Count; i++)
            {
                DGConsumo.Rows.Add(temp.Rows[i]["idproducto"].ToString(),temp.Rows[i]["nombre"].ToString(),"");
            }

            DGConsumo.Columns["idproducto"].Visible = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < DGConsumo.Rows.Count; i++)
                {
                    if (DGConsumo.Rows[i].Cells[2].Value.ToString() != "")
                    {
                        consumo c = new consumo();
                        c.hab = habitacion;
                        c.prod = DGConsumo.Rows[i].Cells[0].Value.ToString();
                        c.cantidad = DGConsumo.Rows[i].Cells[2].Value.ToString();
                        c.fecha = DateTime.Now.ToShortDateString();
                        ConsumoDataAccess cdal = new ConsumoDataAccess();
                        cdal.NuevoConsumo(c);
                        
                    }
                }
                this.Close();
            }
            catch (Exception ex)
            {
 
            }
        }

    }
}
